#ifndef NR_STD_H
#define NR_STD_H

#include <QtCore\QtCore>

typedef enum nr_error_enum
{
    NR_ERROR_NONE = 0,
    NR_ERROR_UNKNOWN,
    NR_ERROR_NOT_VALID_PARAMETER,
    NR_ERROR_NOT_IMPLEMENTED,
    NR_ERROR_NOT_ENOUGH_MEMORY,
    NR_ERROR_NOT_SUPPORT,
    NR_ERROR_NAME_CONFLICTED,
    NR_ERROR_PARSE_XML_FAILED,
    NR_ERROR_OPEN_FILE_FAILED,
    NR_ERROR_LOAD_MODULE_FAILED,
    NR_ERROR_RESOLVE_SYMBOL_FAILED,
    NR_ERROR_CHANNEL_NOT_FOUND,
    NR_ERROR_DEVICE_NOT_FOUND,
    NR_ERROR_CREATE_DEVICE_FAILED,
    NR_ERROR_NOT_LOGIN,
    NR_ERROR_NETWORK_FAILED,
    NR_ERROR_INVALID_PORT,
    NR_ERROR_NETWORK_PORT_USED,
    NR_ERROR_COMMAND_NOT_SUPPORT,
    NR_ERROR_DATABASE_CONNECT_FAILED,
    NR_ERROR_DATABASE_NOT_CONNECT,
}nr_error_t;

typedef enum nr_object_type_enum
{
    NR_OBJECT_UNKNOWN = 0,

    NR_OBJECT_REQUEST_LOGIN,
    NR_OBJECT_REPLY_LOGIN,

    NR_OBJECT_REQUEST_LOGOUT,
    NR_OBJECT_REPLY_LOGOUT,

    NR_OBJECT_REQUEST_GET_ITEMS,
    NR_OBJECT_REPLY_GET_ITEMS,

    NR_OBJECT_REQUEST_START_DATA,
    NR_OBJECT_REPLY_START_DATA,

    NR_OBJECT_REQUEST_STOP_DATA,
    NR_OBJECT_REPLY_STOP_DATA,

    NR_OBJECT_REQUEST_QUERY_DATA,
    NR_OBJECT_REPLY_QUERY_DATA,

    NR_OBJECT_OBJECT_MANAGER,

    NR_OBJECT_DEVICE_TYPE_MANAGER,
    NR_OBJECT_DEVICE_TYPE,

    NR_OBJECT_DEVICE_ITEM_MANAGER,
    NR_OBJECT_DEVICE_ITEM_SERVER,
    NR_OBJECT_DEVICE_GROUP,
    NR_OBJECT_DEVICE_ITEM,
    
    NR_OBJECT_IO_MANAGER,

    NR_OBJECT_SCHEDULER_MANAGER,
    NR_OBJECT_SCHEDULER,

    NR_OBJECT_USER_ROLE_MANAGER,
    NR_OBJECT_ROLES,
    NR_OBJECT_ROLE,
    NR_OBJECT_USERS,
    NR_OBJECT_USER,

    NR_CHANNEL_MANAGER,
    NR_CHANNEL_INPUT,
    NR_CHANNEL_OUTPUT,

} nr_object_type_t;

typedef enum nr_event_category_enum
{

}nr_event_category_t;

typedef quint32 nr_id_t;

typedef QString nr_device_id_t;

typedef nr_device_id_t nr_group_id_t;

typedef nr_device_id_t nr_object_id_t;

#define NR_INVALID_ID ((nr_id_t)-1)

#define NR_INVALID_PORT ((quint16)-1)

#define NR_NET_DEFAULT_PORT 9000

#define NR_SUCCEED(status) (status == NR_ERROR_NONE)
#define NR_FAILED(status) (status != NR_ERROR_NONE)

#define NR_CHECK_RETURN(status) { if(NR_FAILED(status)) return status; }

#define NR_ASSERT_RETURN(status) { if(NR_FAILED(status)) { Q_ASSERT(false); return status; }}

#define NR_ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))

// Convert the QT string to mongodb string (UTF8)
#define NR_STRING_Q2M(s) (s.toUtf8().data())

// Convert the mongodb string (UTF8) to QT string 
#define NR_STRING_M2Q(s) (QString::fromUtf8(s))

#endif